package com.bawei.mvvm.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bawei.mvvm.R
import com.bawei.mvvm.databinding.ItemBinding
import com.bawei.mvvm.entity.Goods

class GoodsAdapter(var list:MutableList<Goods>): RecyclerView.Adapter<GoodsAdapter.GoodsViewHolder>() {

    //创建viewholder
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GoodsViewHolder {

         var  itemBinding = DataBindingUtil.inflate<ItemBinding>(LayoutInflater.from(parent.context), R.layout.item,parent,false)
        Log.d("ytx1111", "onCreateViewHolder: ")
        return GoodsViewHolder(itemBinding)
    }
    //绑定数据
    override fun onBindViewHolder(holder: GoodsViewHolder, position: Int) {
       holder.itemBinding.goods = list[position]
        Log.d("ytx1111", "onBindViewHolder: ")
    }

    override fun getItemCount(): Int {
        return list.size
    }


    inner class GoodsViewHolder(var itemBinding: ItemBinding): RecyclerView.ViewHolder(itemBinding.root) {

    }

}